package sdmakerz_v1.coresyntax.generator;

import com.google.common.base.Objects;
import org.eclipse.emf.common.util.EList;
import org.eclipse.xtend2.lib.StringConcatenation;
import sdmakerz_v1.coresyntax.generator.interfaces.IConfigData;
import sdmakerz_v1.coresyntax.sDMakerV1.Config;
import sdmakerz_v1.coresyntax.sDMakerV1.DoubleExp;
import sdmakerz_v1.coresyntax.sDMakerV1.IntegerExp;

/**
 * Une classe qui simplfie la recuperation des donnees d'une Config
 * @author pstl-team
 */
@SuppressWarnings("all")
public class ConfigDataImpl implements IConfigData {
  private boolean isEmptyConfig;
  
  private boolean withEsperanceLongueurTracesUniformes;
  
  private boolean withMemUsed;
  
  private boolean withNbObservations;
  
  private boolean withTailleFSA;
  
  private boolean withPrecision;
  
  private int precisionNb;
  
  private boolean precisionTracesCompletes;
  
  private boolean withRecall;
  
  private int recallNb;
  
  private boolean recallUseUniformTraces;
  
  private boolean recallTracesCompletes;
  
  private boolean withTailleTraces;
  
  private int tailleTracesNbUniformes;
  
  private String configName;
  
  private double globalProbInAlt;
  
  private double probContinueLoop;
  
  private double probExecOpt;
  
  /**
   * ** INITIALIZERS **
   */
  public void init(final Config config) {
    this.withEsperanceLongueurTracesUniformes = false;
    this.withMemUsed = false;
    this.withNbObservations = false;
    this.withTailleFSA = false;
    this.withPrecision = false;
    int _minus = (-1);
    this.precisionNb = _minus;
    this.precisionTracesCompletes = false;
    this.withRecall = false;
    int _minus_1 = (-1);
    this.recallNb = _minus_1;
    this.recallUseUniformTraces = false;
    this.recallTracesCompletes = false;
    this.withTailleTraces = false;
    int _minus_2 = (-1);
    this.tailleTracesNbUniformes = _minus_2;
    int _minus_3 = (-1);
    this.globalProbInAlt = _minus_3;
    int _minus_4 = (-1);
    this.probContinueLoop = _minus_4;
    int _minus_5 = (-1);
    this.probExecOpt = _minus_5;
    boolean _equals = Objects.equal(config, null);
    this.isEmptyConfig = _equals;
    boolean _equals_1 = (this.isEmptyConfig == false);
    if (_equals_1) {
      String _name = config.getName();
      this.configName = _name;
      boolean _and = false;
      boolean _and_1 = false;
      DoubleExp _globalProbInAlt = config.getGlobalProbInAlt();
      boolean _notEquals = (!Objects.equal(_globalProbInAlt, null));
      if (!_notEquals) {
        _and_1 = false;
      } else {
        DoubleExp _globalProbInAlt_1 = config.getGlobalProbInAlt();
        double _value = _globalProbInAlt_1.getValue();
        boolean _lessThan = (0 < _value);
        _and_1 = (_notEquals && _lessThan);
      }
      if (!_and_1) {
        _and = false;
      } else {
        DoubleExp _globalProbInAlt_2 = config.getGlobalProbInAlt();
        double _value_1 = _globalProbInAlt_2.getValue();
        boolean _lessEqualsThan = (_value_1 <= 1);
        _and = (_and_1 && _lessEqualsThan);
      }
      if (_and) {
        DoubleExp _globalProbInAlt_3 = config.getGlobalProbInAlt();
        double _value_2 = _globalProbInAlt_3.getValue();
        this.globalProbInAlt = _value_2;
      }
      boolean _and_2 = false;
      boolean _and_3 = false;
      DoubleExp _probContinueLoop = config.getProbContinueLoop();
      boolean _notEquals_1 = (!Objects.equal(_probContinueLoop, null));
      if (!_notEquals_1) {
        _and_3 = false;
      } else {
        DoubleExp _probContinueLoop_1 = config.getProbContinueLoop();
        double _value_3 = _probContinueLoop_1.getValue();
        boolean _lessThan_1 = (0 < _value_3);
        _and_3 = (_notEquals_1 && _lessThan_1);
      }
      if (!_and_3) {
        _and_2 = false;
      } else {
        DoubleExp _probContinueLoop_2 = config.getProbContinueLoop();
        double _value_4 = _probContinueLoop_2.getValue();
        boolean _lessEqualsThan_1 = (_value_4 <= 1);
        _and_2 = (_and_3 && _lessEqualsThan_1);
      }
      if (_and_2) {
        DoubleExp _probContinueLoop_3 = config.getProbContinueLoop();
        double _value_5 = _probContinueLoop_3.getValue();
        this.probContinueLoop = _value_5;
      }
      boolean _and_4 = false;
      boolean _and_5 = false;
      DoubleExp _probExecOpt = config.getProbExecOpt();
      boolean _notEquals_2 = (!Objects.equal(_probExecOpt, null));
      if (!_notEquals_2) {
        _and_5 = false;
      } else {
        DoubleExp _probExecOpt_1 = config.getProbExecOpt();
        double _value_6 = _probExecOpt_1.getValue();
        boolean _lessThan_2 = (0 < _value_6);
        _and_5 = (_notEquals_2 && _lessThan_2);
      }
      if (!_and_5) {
        _and_4 = false;
      } else {
        DoubleExp _probExecOpt_2 = config.getProbExecOpt();
        double _value_7 = _probExecOpt_2.getValue();
        boolean _lessEqualsThan_2 = (_value_7 <= 1);
        _and_4 = (_and_5 && _lessEqualsThan_2);
      }
      if (_and_4) {
        DoubleExp _probExecOpt_3 = config.getProbExecOpt();
        double _value_8 = _probExecOpt_3.getValue();
        this.probExecOpt = _value_8;
      }
      EList<String> _cmds = config.getCmds();
      for (final String cmd : _cmds) {
        int _compareTo = cmd.compareTo("esperanceLongueurTracesUniformes");
        boolean _equals_2 = (_compareTo == 0);
        if (_equals_2) {
          this.withEsperanceLongueurTracesUniformes = true;
        } else {
          int _compareTo_1 = cmd.compareTo("memUsed");
          boolean _equals_3 = (_compareTo_1 == 0);
          if (_equals_3) {
            this.withMemUsed = true;
          } else {
            int _compareTo_2 = cmd.compareTo("nbObservations");
            boolean _equals_4 = (_compareTo_2 == 0);
            if (_equals_4) {
              this.withNbObservations = true;
            } else {
              int _compareTo_3 = cmd.compareTo("precision");
              boolean _equals_5 = (_compareTo_3 == 0);
              if (_equals_5) {
                this.withPrecision = true;
                IntegerExp _precisionNb = config.getPrecisionNb();
                int _value_9 = _precisionNb.getValue();
                this.precisionNb = _value_9;
                String _precisionTracesCompletes = config.getPrecisionTracesCompletes();
                boolean _notEquals_3 = (!Objects.equal(_precisionTracesCompletes, null));
                this.precisionTracesCompletes = _notEquals_3;
              } else {
                int _compareTo_4 = cmd.compareTo("recall");
                boolean _equals_6 = (_compareTo_4 == 0);
                if (_equals_6) {
                  this.withRecall = true;
                  int _recallNb = config.getRecallNb();
                  this.recallNb = _recallNb;
                  String _recallUseUniformTraces = config.getRecallUseUniformTraces();
                  boolean _notEquals_4 = (!Objects.equal(_recallUseUniformTraces, null));
                  this.recallUseUniformTraces = _notEquals_4;
                  String _recallTracesCompletes = config.getRecallTracesCompletes();
                  boolean _notEquals_5 = (!Objects.equal(_recallTracesCompletes, null));
                  this.recallTracesCompletes = _notEquals_5;
                } else {
                  int _compareTo_5 = cmd.compareTo("tailleFSA");
                  boolean _equals_7 = (_compareTo_5 == 0);
                  if (_equals_7) {
                    this.withTailleFSA = true;
                  } else {
                    int _compareTo_6 = cmd.compareTo("tailleTraces");
                    boolean _equals_8 = (_compareTo_6 == 0);
                    if (_equals_8) {
                      this.withTailleTraces = true;
                      IntegerExp _tailleTracesNbUniformes = config.getTailleTracesNbUniformes();
                      int _value_10 = _tailleTracesNbUniformes.getValue();
                      this.tailleTracesNbUniformes = _value_10;
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  
  /**
   * ** GETTERS **
   */
  public double globalProbInAlt() {
    return this.globalProbInAlt;
  }
  
  public double probContinueLoop() {
    return this.probContinueLoop;
  }
  
  public double probExecOpt() {
    return this.probExecOpt;
  }
  
  public String getConfigName() {
    return this.configName;
  }
  
  /**
   * ** OTHERS **
   */
  public CharSequence printImports() {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence charSequenceResult = _builder;
    boolean _equals = (this.isEmptyConfig == false);
    if (_equals) {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("import evaluation.*;");
      String _plus = (charSequenceResult + _builder_1.toString());
      charSequenceResult = _plus;
    }
    return charSequenceResult;
  }
  
  public CharSequence printEval() {
    StringConcatenation _builder = new StringConcatenation();
    CharSequence charSequenceResult = _builder;
    boolean _equals = (this.isEmptyConfig == false);
    if (_equals) {
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("/* from config ");
      _builder_1.append(this.configName, "");
      _builder_1.append(" */");
      _builder_1.newLineIfNotEmpty();
      _builder_1.append("Evaluator evaluator= new Evaluator(");
      _builder_1.newLine();
      _builder_1.append("new Evaluator_Config() {");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("@Override");
      _builder_1.newLine();
      _builder_1.append("\t");
      _builder_1.append("public void config() {");
      _builder_1.newLine();
      {
        if (this.withEsperanceLongueurTracesUniformes) {
          _builder_1.append("\t\t");
          _builder_1.append("new EsperanceLongueurTracesUniformes();");
          _builder_1.newLine();
        }
      }
      {
        if (this.withMemUsed) {
          _builder_1.append("\t\t");
          _builder_1.append("new MemUsed();");
          _builder_1.newLine();
        }
      }
      {
        if (this.withNbObservations) {
          _builder_1.append("\t\t");
          _builder_1.append("new NbObservations();");
          _builder_1.newLine();
        }
      }
      {
        if (this.withPrecision) {
          _builder_1.append("\t\t");
          _builder_1.append("new Precision(");
          _builder_1.append(this.precisionNb, "		");
          _builder_1.append(", ");
          _builder_1.append(this.precisionTracesCompletes, "		");
          _builder_1.append(");");
          _builder_1.newLineIfNotEmpty();
        }
      }
      {
        if (this.withRecall) {
          _builder_1.append("\t\t");
          _builder_1.append("new Recall(");
          _builder_1.append(this.recallUseUniformTraces, "		");
          _builder_1.append(", ");
          _builder_1.append(this.recallNb, "		");
          _builder_1.append(", ");
          _builder_1.append(this.recallTracesCompletes, "		");
          _builder_1.append(");");
          _builder_1.newLineIfNotEmpty();
        }
      }
      {
        if (this.withTailleFSA) {
          _builder_1.append("\t\t");
          _builder_1.append("new TailleFSA();");
          _builder_1.newLine();
        }
      }
      {
        if (this.withTailleTraces) {
          _builder_1.append("\t\t");
          _builder_1.append("new TailleTrace(");
          _builder_1.append(this.tailleTracesNbUniformes, "		");
          _builder_1.append(");");
          _builder_1.newLineIfNotEmpty();
        }
      }
      _builder_1.append("\t");
      _builder_1.append("}");
      _builder_1.newLine();
      _builder_1.append("});");
      _builder_1.newLine();
      _builder_1.newLine();
      _builder_1.append("System.out.println(\"Begin evaluation with ");
      _builder_1.append(this.configName, "");
      _builder_1.append(": \");");
      _builder_1.newLineIfNotEmpty();
      _builder_1.append("evaluator.eval(\"\");");
      _builder_1.newLine();
      _builder_1.append("System.out.println(\"End evaluation with ");
      _builder_1.append(this.configName, "");
      _builder_1.append("\");");
      _builder_1.newLineIfNotEmpty();
      charSequenceResult = _builder_1;
    }
    return charSequenceResult;
  }
}
